package com.soul.server.controller;

import com.soul.server.server.MessagesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author mdoya
 * @version 1.0
 * @description:
 */
@Slf4j
@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 通过环信id查询用户信息
     * @param huanxinId 环信用户名
     * @return
     */
    @RequestMapping(path = "/userinfo",method = RequestMethod.GET)
    public ResponseEntity findUserInfo(String huanxinId){
        return ResponseEntity.ok(messagesService.findUserInfo(huanxinId));
    }

    /**
     *  添加联系人
     * @param params 对象
     * @return
     */
    @RequestMapping(path = "/contacts",method = RequestMethod.POST)
    public ResponseEntity addContacts(@RequestBody Map<String,String> params){
        messagesService.addContacts(Long.valueOf(params.get("userId")));
        return ResponseEntity.ok(null);
    }

    /**
     *  联系人列表查询分页
     * @param page 每页
     * @param pagesize 每页条数
     * @param keyword 关键字
     * @return ResponseEntity
     */
    @RequestMapping(path = "/contacts",method = RequestMethod.GET)
    public ResponseEntity findpageContacts(@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10") Long pagesize,String keyword){
        return ResponseEntity.ok(messagesService.findpageContacts(page,pagesize,keyword));
    }
}
